#include "Comm.hpp"
#include "Pipe.hpp"
int main()
{
    // 1.获取k值
    key_t key = GetShmKeyorDie();
    cout << "key:" << ToHex(key) << endl;
    sleep(2);

    // 2.创建共享内存
    int shmid = CreatShm(key, defaultsize);
    cout << "shmid:" << shmid << endl;
    // ShmDebug(shmid);
    //  sleep(2);

    // 3.将共享内存和进程进行挂接
    char *addr = (char *)ShmAttach(shmid);
    cout << "Attach shm success, addr: " << ToHex((uint64_t)addr) << endl;

    Fifo fifo;
    Sync syn;
    syn.OpenPipeOrDie();

    // sleep(5);
    for (;;)
    {
        if(!syn.Wait()) break;
        cout << "client content: " << addr << endl;
        sleep(1);
    }

    ShmDetach(addr);
    cout << "Detach shm success, addr: " << ToHex((uint64_t)addr) << endl;

    sleep(5);
    DeleteShm(shmid);

    return 0;
}